import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login'

//处理二次点击的报错
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (location) {
  return originalPush.call(this, location).catch(err => {
  })
};


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Login',
    component: Login
  },
  {
    path: '/index',
    name: 'Index',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Index')
  },
  {
    path: "/client",
    name: "Client",
    component: () => import(/* webpackChunkName: "about" */ "../views/Client")
  },
  {
    path: "/orders",
    name: "Orders",
    component: () => import(/* webpackChunkName: "about" */ "../views/Orders"),
    children: [
      {
        path: "/orders/allOrders",
        component: () => import (/* webpackChunkName: "about" */"../components/allOrders/allOrders"),
        meta: {
          activeNum: 0
        }
      },
      {
        path: "/orders/pendingSend",
        component: () => import(/* webpackChunkName: "about" */"../components/pendingSend"),
        meta: {
          activeNum: 1
        }
      },
      {
        path: "/orders/pendingReceive",
        component: () => import(/* webpackChunkName: "about" */"../components/pendingReceive"),
        meta: {
          activeNum: 2
        }
      },
      {
        path: "pendingComment",//前面也可以不写"/orders"
        component: () => import(/* webpackChunkName: "about" */"../components/pendingComment"),
        meta: {
          activeNum: 3
        }
      }
    ]
  },
  {
    path: "/message",
    name: "Message",
    component: () => import(/* webpackChunkName: "about" */ "../views/Message"),

    children: [
      {
        path: "/message/:id",
        component: () => import(/* webpackChunkName: "about" */ "../components/MessageDetail")
      }
    ]
  }

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
